<template>
	<detailbox :title="type == 1 ? '重新编辑' : '新增'" @leftclick="close">
		<div slot="right" class="flex_item flex_between">
			<div v-if="type == 1" class="error error_f f12 ml10 flex_start">
				<i class="f14 el-icon-error"></i>
				审核未通过:
				<span class="ml30">
					{{ checkItem.type == 1 ? '审核人:' : checkItem.type == 3 ? '记录责任人:' : checkItem.type == 4 ? '批准人:' : '' }} {{ checkItem.createUserName }}
				</span>
				<span class="ml30">未通过原因: {{ checkItem.content }}</span>
			</div>
			<div v-else></div>
			<div class="flex_end">
				<el-button type="success" size="small" @click="addFile" v-if="type != 1">添加新增</el-button>
				<el-button v-if="type == 1" type="primary" size="small" plain @click="openDialg('showhistory')">审批历史详情</el-button>
				<el-button type="primary" size="small" @click="submit">提交</el-button>
			</div>
		</div>
		<el-row>
			<el-col :span="18">
				<div style="margin-top:10px;" v-for="(form, index) in formList" :key="index" :id="'item' + index">
					<basic-container>
						<div class="main_title success_f flex_between">
							<b>
								管理信息
								<span v-if="formList.length > 1">({{ index + 1 }})</span>
							</b>
							<el-button type="danger" size="small" plain v-if="index != 0" @click="delFile(index)">删除</el-button>
						</div>
						<el-divider></el-divider>
						<div class="mb20">
							<span class="index_num success_bg">1</span>
							<b class="f14">基础信息</b>
						</div>
						<div>
							<el-form size="small" inline model="form">
								<el-row>
									<el-col :span="12">
										<el-form-item label="风险管理编号:" required>
											<el-input v-model="form.number" placeholder="数据带入" class="w160 ml10" readonly v-if="form.numberType == 0"></el-input>
											<el-input class="ml10 w160" placeholder="请输入" v-model="form.number" v-if="form.numberType == 1"></el-input>
											<el-popover placement="top-start" title="编号规则:" width="220" trigger="hover">
												<div>
													<p>FXGL--------风险管理</p>
													<p>xxxx---------年月日(编辑日期，8位)</p>
													<p>xx---------流水号,从01开始</p>
												</div>
												<i slot="reference" class="el-icon-question f18 gray_f ml10"></i>
											</el-popover>
										</el-form-item>
									</el-col>
									<el-col :span="12">
										<el-form-item label="风险管理计划编号:" required>
											<el-select class="w160" placeholder="请选择" v-model="form.planNumber" filterable @change="changplan($event, form)">
												<el-option v-for="(item, i) in developmentplanList" :key="i" :label="item.number" :value="item.number"></el-option>
											</el-select>
										</el-form-item>
									</el-col>
								</el-row>
								<el-row>
									<el-col :span="12">
										<el-form-item label="风险管理名称:" required><el-input v-model="form.name" placeholder="请输入"></el-input></el-form-item>
									</el-col>
									<el-col :span="12">
										<el-form-item label="产品名称:" required>
											<el-input class="w160" v-model="form.productName" placeholder="数据带入" readonly></el-input>
										</el-form-item>
									</el-col>
									<el-col :span="12">
										<el-form-item label="产品编号:" required>
											<el-input class="w160" v-model="form.productCode" placeholder="数据带入" readonly></el-input>
										</el-form-item>
									</el-col>
									<el-col :span="12">
										<el-form-item label="规格型号:" required>
											<el-input class="w160" v-model="form.skus" placeholder="数据带入" readonly></el-input>
										</el-form-item>
									</el-col>

									<el-col :span="12">
										<el-form-item label="管理部门:" required>
											<el-cascader
												class="w160"
												placeholder="请选择"
												ref="newdept"
												:options="deptOption"
												v-model="form.manageDeptId"
												:show-all-levels="false"
												:props="{
													value: 'id',
													label: 'deptName',
													emitPath: false,
													checkStrictly: true
												}"
												filterable
												@change="getMemberOption($event, index)"
											></el-cascader>
										</el-form-item>
									</el-col>
									<el-col :span="12">
										<el-form-item label="负责人:" required>
											<el-select class="w160" placeholder="请选择" v-model="form.manageUserId" filterable @change="selectChange($event, form)">
												<el-option v-for="item in form.memberOption" :key="item.id" :value="item.id" :label="item.name"></el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="12">
										<el-form-item label="编制部门:" class="">
											<el-input class="w160" v-model="userInfo.deptName" placeholder="数据带入" readonly></el-input>
										</el-form-item>
									</el-col>
								</el-row>
							</el-form>

							<!-- 管理计划 -->
							<div class="reviewTitle flex_start mb20"><b>风险管理</b></div>
							<div class="reviewList">
								<el-form size="small">
									<el-form-item label="产品状态:" required>
										<el-select class="w160" v-model="form.productStatus">
											<el-option label="正常状态" :value="0"></el-option>
											<el-option label="故障状态" :value="1"></el-option>
										</el-select>
									</el-form-item>
								</el-form>
								<div class=" f14 flex_start mb20">
									<i class="error_f">*</i>
									<b>风险分析、评价和控制</b>
									<el-button type="primary" size="mini" class="el-icon-circle-plus-outline ml10" plain @click="addList(form)">增加</el-button>
								</div>
								<div class="mb20 wp100" v-for="(item, i) in form.controlList" :key="i">
									<div class="flex_row reviewList gray_bg">
										<div style="width:30px;">{{ i + 1 }} 、</div>
										<el-form size="small" label-width="auto" :inline="false" style="width: 100%;">
											<el-form-item class="ml0">
												<div slot="label">
													<span class="red_f">*</span>
													危险（源）:
													<el-popover placement="top-start" title="危险源示例" width="700" trigger="hover">
														<wyy></wyy>
														<i slot="reference" class="el-icon-question f18 gray_f"></i>
													</el-popover>
												</div>
												<el-select v-model="item.wxy1" allow-create default-first-option filterable placeholder="请输入/创建/选择" style="width:86%;">
													<el-option v-for="v in wxyList" :key="v" :label="v" :value="v"></el-option>
												</el-select>
												<!-- <el-input placeholder="请输入" v-model="item.wxy1"></el-input> -->
											</el-form-item>
											<el-form-item class="ml0">
												<div slot="label">
													<span class="red_f">*</span>
													事件序列:
													<el-popover placement="top-start" title="事件序列" width="700" trigger="hover">
														<wyy></wyy>
														<i slot="reference" class="el-icon-question f18 gray_f"></i>
													</el-popover>
												</div>
												<el-select v-model="item.sjxl1" allow-create default-first-option filterable placeholder="请输入/创建/选择" style="width:86%;">
													<el-option v-for="v in sjxlList" :key="v" :label="v" :value="v"></el-option>
												</el-select>
												<!-- <el-input placeholder="请输入" v-model="item.sjxl1"></el-input> -->
											</el-form-item>
											<el-form-item class="ml0" label="危险情况:" required>
												<el-select v-model="item.wxqk1" allow-create default-first-option filterable placeholder="请输入/创建/选择" style="width:86%;">
													<el-option v-for="v in wxqkList" :key="v" :label="v" :value="v"></el-option>
												</el-select>
												<!-- <el-input placeholder="请输入" v-model="item.wxqk1"></el-input> -->
											</el-form-item>
											<el-form-item class="ml0" label="伤害:" required>
												<el-select v-model="item.sh1" allow-create default-first-option filterable placeholder="请输入/创建/选择" style="width:86%;">
													<el-option v-for="v in shList" :key="v" :label="v" :value="v"></el-option>
												</el-select>
												<!-- <el-input placeholder="请输入" v-model="item.sh1"></el-input> -->
											</el-form-item>

											<el-row class="flex_wrap">
												<el-col :span="8">
													<el-form-item class="ml0" label="概率分级:" required>
														<el-select
															class="w160"
															v-model="item.glfj1"
															filterable
															placeholder="请选择"
															@change="changfxitem($event, 'fxgl', item, 'yzfj1', 'glfj1', 'fxpj1')"
														>
															<el-option :label="jhdata.fxgl[P1]" value="P1"></el-option>
															<el-option :label="jhdata.fxgl[P2]" value="P2"></el-option>
															<el-option :label="jhdata.fxgl[P3]" value="P3"></el-option>
															<el-option :label="jhdata.fxgl[P4]" value="P4"></el-option>
															<el-option :label="jhdata.fxgl[P5]" value="P5"></el-option>
														</el-select>
													</el-form-item>
												</el-col>
												<el-col :span="8">
													<el-form-item class="ml0" label="严重度水平分级:" required>
														<el-select
															class="w160"
															v-model="item.yzfj1"
															filterable
															placeholder="请选择"
															@change="changfxitem($event, 'fxyzd', item, 'yzfj1', 'glfj1', 'fxpj1')"
														>
															<el-option :label="jhdata.fxyzd[S1]" value="S1"></el-option>
															<el-option :label="jhdata.fxyzd[S2]" value="S2"></el-option>
															<el-option :label="jhdata.fxyzd[S3]" value="S3"></el-option>
															<el-option :label="jhdata.fxyzd[S4]" value="S4"></el-option>
															<el-option :label="jhdata.fxyzd[S5]" value="S5"></el-option>
														</el-select>
													</el-form-item>
												</el-col>
												<el-col :span="8">
													<el-form-item class="ml0" label="风险评价:" label-width="100" required>
														<el-input class="w160" placeholder="数据带入" v-model="item.fxpj1"></el-input>
													</el-form-item>
												</el-col>
												<el-col :span="8">
													<el-form-item class="ml0" label="是否需要降低风险:" required>
														<el-select class="w160" placeholder="请选择" v-model="item.jdfx1">
															<el-option label="否" value="0"></el-option>
															<el-option label="是" value="1"></el-option>
														</el-select>
													</el-form-item>
												</el-col>
												<template v-if="item.jdfx1 == 1">
													<el-col :span="16">
														<el-form-item class="ml0" label="风险控制措施:" required>
															<el-input placeholder="请输入" v-model="item.kzcs1"></el-input>
														</el-form-item>
													</el-col>
												</template>
												<el-col :span="8">
													<el-form-item class="ml0" label="是否有剩余风险:" required>
														<el-select class="w160" placeholder="请选择" v-model="item.syfx1">
															<el-option label="否" value="0"></el-option>
															<el-option label="是" value="1"></el-option>
														</el-select>
													</el-form-item>
												</el-col>
												<template v-if="item.syfx1 == 1">
													<el-col :span="16">
														<el-form-item class="ml0" label="剩余风险/产品受益:" required>
															<el-select v-model="item.fxsy2">
																<el-option label="剩余风险大于产品受益" value="0"></el-option>
																<el-option label="产品受益大于剩余风险" value="1"></el-option>
															</el-select>
														</el-form-item>
													</el-col>
												</template>
											</el-row>

											<template v-if="item.syfx1 == 1">
												<div class="reviewList white_bg mb20">
													<div class="f14 mb20"><b>剩余风险分析、评价和控制:</b></div>
													<el-form size="small" label-width="auto" :inline="false">
														<el-form-item class="ml0">
															<div slot="label">
																<span class="red_f">*</span>
																危险（源）:
																<el-popover placement="top-start" title="危险源示例" width="700" trigger="hover">
																	<wyy></wyy>
																	<i slot="reference" class="el-icon-question f18 gray_f"></i>
																</el-popover>
															</div>
															<el-select
																v-model="item.wxy2"
																allow-create
																default-first-option
																filterable
																placeholder="请输入/创建/选择"
																style="width:86%;"
															>
																<el-option v-for="v in wxyList" :key="v" :label="v" :value="v"></el-option>
															</el-select>
															<!-- <el-input placeholder="请输入" v-model="item.wxy2"></el-input> -->
														</el-form-item>
														<el-form-item class="ml0">
															<div slot="label">
																<span class="red_f">*</span>
																事件序列:
																<el-popover placement="top-start" title="事件序列" width="700" trigger="hover">
																	<wyy></wyy>
																	<i slot="reference" class="el-icon-question f18 gray_f"></i>
																</el-popover>
															</div>
															<el-select
																v-model="item.sjxl2"
																allow-create
																default-first-option
																filterable
																placeholder="请输入/创建/选择"
																style="width:86%;"
															>
																<el-option v-for="v in sjxlList" :key="v" :label="v" :value="v"></el-option>
															</el-select>
															<!-- <el-input placeholder="请输入" v-model="item.sjxl2"></el-input> -->
														</el-form-item>
														<el-form-item class="ml0" label="危险情况:" required>
															<el-select
																v-model="item.wxqk2"
																allow-create
																default-first-option
																filterable
																placeholder="请输入/创建/选择"
																style="width:86%;"
															>
																<el-option v-for="v in wxqkList" :key="v" :label="v" :value="v"></el-option>
															</el-select>
															<!-- <el-input placeholder="请输入" v-model="item.wxqk2"></el-input> -->
														</el-form-item>
														<el-form-item class="ml0" label="伤害:" required>
															<el-select
																v-model="item.sh2"
																allow-create
																default-first-option
																filterable
																placeholder="请输入/创建/选择"
																style="width:86%;"
															>
																<el-option v-for="v in shList" :key="v" :label="v" :value="v"></el-option>
															</el-select>
															<!-- <el-input placeholder="请输入" v-model="item.sh2"></el-input> -->
														</el-form-item>
														<el-row class="flex_wrap">
															<el-col :span="8">
																<el-form-item class="ml0" label="概率分级:" required>
																	<el-select
																		class="w160"
																		v-model="item.glfj2"
																		filterable
																		placeholder="请选择"
																		@change="changfxitem($event, 'fxgl', item, 'yzfj2', 'glfj2', 'fxpj2')"
																	>
																		<el-option :label="jhdata.fxgl[P1]" value="P1"></el-option>
																		<el-option :label="jhdata.fxgl[P2]" value="P2"></el-option>
																		<el-option :label="jhdata.fxgl[P3]" value="P3"></el-option>
																		<el-option :label="jhdata.fxgl[P4]" value="P4"></el-option>
																		<el-option :label="jhdata.fxgl[P5]" value="P5"></el-option>
																	</el-select>
																</el-form-item>
															</el-col>
															<el-col :span="8">
																<el-form-item class="ml0" label="严重度水平分级:" required>
																	<el-select
																		class="w160"
																		v-model="item.yzfj2"
																		filterable
																		placeholder="请选择"
																		@change="changfxitem($event, 'fxyzd', item, 'yzfj2', 'glfj2', 'fxpj2')"
																	>
																		<el-option :label="jhdata.fxyzd[S1]" value="S1"></el-option>
																		<el-option :label="jhdata.fxyzd[S2]" value="S2"></el-option>
																		<el-option :label="jhdata.fxyzd[S3]" value="S3"></el-option>
																		<el-option :label="jhdata.fxyzd[S4]" value="S4"></el-option>
																		<el-option :label="jhdata.fxyzd[S5]" value="S5"></el-option>
																	</el-select>
																</el-form-item>
															</el-col>
															<el-col :span="8">
																<el-form-item class="ml0" label="风险评价:" label-width="100" required>
																	<el-input class="w160" placeholder="数据带入" v-model="item.fxpj2"></el-input>
																</el-form-item>
															</el-col>
															<el-col :span="8">
																<el-form-item class="ml0" label="是否需要降低风险:" required>
																	<el-select class="w160" placeholder="请选择" v-model="item.jdfx2">
																		<el-option label="否" value="0"></el-option>
																		<el-option label="是" value="1"></el-option>
																	</el-select>
																</el-form-item>
															</el-col>
															<template v-if="item.jdfx2 == 1">
																<el-col :span="16">
																	<el-form-item class="ml0" label="风险控制措施:" required>
																		<el-input placeholder="请输入" v-model="item.kzcs2"></el-input>
																	</el-form-item>
																</el-col>
															</template>
															<el-col :span="8">
																<el-form-item class="ml0" label="是否有剩余风险:" required>
																	<el-select class="w160" placeholder="请选择" v-model="item.syfx2">
																		<el-option label="否" value="0"></el-option>
																		<el-option label="是" value="1"></el-option>
																	</el-select>
																</el-form-item>
															</el-col>
															<template v-if="item.syfx2 == 1">
																<el-col :span="16">
																	<el-form-item class="ml0" label="剩余风险/产品受益:" required>
																		<el-select v-model="item.fxsy2">
																			<el-option label="剩余风险大于产品受益" value="0"></el-option>
																			<el-option label="产品受益大于剩余风险" value="1"></el-option>
																		</el-select>
																	</el-form-item>
																</el-col>
															</template>
														</el-row>
													</el-form>
												</div>
											</template>
											<template v-if="item.fxsy2 == 1 && item.syfx1 == 1 && item.syfx2 == 1">
												<div class="reviewList white_bg">
													<div class="f14 mb20"><b>剩余风险大于产品受益的风险分析、评价和控制:</b></div>

													<el-form size="small" label-width="auto" :inline="false">
														<el-form-item class="ml0">
															<div slot="label">
																<span class="red_f">*</span>
																危险（源）:
																<el-popover placement="top-start" title="危险源示例" width="700" trigger="hover">
																	<wyy></wyy>
																	<i slot="reference" class="el-icon-question f18 gray_f"></i>
																</el-popover>
															</div>
															<el-select
																v-model="item.wxy3"
																allow-create
																default-first-option
																filterable
																placeholder="请输入/创建/选择"
																style="width:86%;"
															>
																<el-option v-for="v in wxyList" :key="v" :label="v" :value="v"></el-option>
															</el-select>
															<!-- <el-input placeholder="请输入" v-model="item.wxy3"></el-input> -->
														</el-form-item>
														<el-form-item class="ml0">
															<div slot="label">
																<span class="red_f">*</span>
																事件序列:
																<el-popover placement="top-start" title="事件序列" width="700" trigger="hover">
																	<wyy></wyy>
																	<i slot="reference" class="el-icon-question f18 gray_f"></i>
																</el-popover>
															</div>
															<el-select
																v-model="item.sjxl3"
																allow-create
																default-first-option
																filterable
																placeholder="请输入/创建/选择"
																style="width:86%;"
															>
																<el-option v-for="v in sjxlList" :key="v" :label="v" :value="v"></el-option>
															</el-select>
															<!-- <el-input placeholder="请输入" v-model="item.sjxl3"></el-input> -->
														</el-form-item>
														<el-form-item class="ml0" label="危险情况:" required>
															<el-select
																v-model="item.wxqj3"
																allow-create
																default-first-option
																filterable
																placeholder="请输入/创建/选择"
																style="width:86%;"
															>
																<el-option v-for="v in wxqkList" :key="v" :label="v" :value="v"></el-option>
															</el-select>
															<!-- <el-input placeholder="请输入" v-model="item.wxqj3"></el-input> -->
														</el-form-item>
														<el-form-item class="ml0" label="伤害:" required>
															<el-select
																v-model="item.sh3"
																allow-create
																default-first-option
																filterable
																placeholder="请输入/创建/选择"
																style="width:86%;"
															>
																<el-option v-for="v in shList" :key="v" :label="v" :value="v"></el-option>
															</el-select>
															<!-- <el-input placeholder="请输入" v-model="item.sh3"></el-input> -->
														</el-form-item>
														<el-row>
															<el-col :span="8">
																<el-form-item class="ml0" label="概率分级:" required>
																	<el-select
																		class="w160"
																		v-model="item.glfj3"
																		filterable
																		placeholder="请选择"
																		@change="changfxitem($event, 'fxgl', item, 'yzfj3', 'glfj3', 'fxpj3')"
																	>
																		<el-option :label="jhdata.fxgl[P1]" value="P1"></el-option>
																		<el-option :label="jhdata.fxgl[P2]" value="P2"></el-option>
																		<el-option :label="jhdata.fxgl[P3]" value="P3"></el-option>
																		<el-option :label="jhdata.fxgl[P4]" value="P4"></el-option>
																		<el-option :label="jhdata.fxgl[P5]" value="P5"></el-option>
																	</el-select>
																</el-form-item>
															</el-col>
															<el-col :span="8">
																<el-form-item class="ml0" label="严重度水平分级:" required>
																	<el-select
																		class="w160"
																		v-model="item.yzfj3"
																		filterable
																		placeholder="请选择"
																		@change="changfxitem($event, 'fxyzd', item, 'yzfj3', 'glfj3', 'fxpj3')"
																	>
																		<el-option :label="jhdata.fxyzd[S1]" value="S1"></el-option>
																		<el-option :label="jhdata.fxyzd[S2]" value="S2"></el-option>
																		<el-option :label="jhdata.fxyzd[S3]" value="S3"></el-option>
																		<el-option :label="jhdata.fxyzd[S4]" value="S4"></el-option>
																		<el-option :label="jhdata.fxyzd[S5]" value="S5"></el-option>
																	</el-select>
																</el-form-item>
															</el-col>
															<el-col :span="8">
																<el-form-item class="ml0" label="风险评价:" label-width="100" required>
																	<el-input class="w160" placeholder="数据带入" v-model="item.fxpj3"></el-input>
																</el-form-item>
															</el-col>
															<el-col :span="8">
																<el-form-item class="ml0" label="是否需要降低风险:" required>
																	<el-select class="w160" placeholder="请选择" v-model="item.jdfx3">
																		<el-option label="否" value="0"></el-option>
																		<el-option label="是" value="1"></el-option>
																	</el-select>
																</el-form-item>
															</el-col>
															<template v-if="item.jdfx3 == 1">
																<el-col :span="16">
																	<el-form-item class="ml0" label="风险控制措施:" required>
																		<el-input class="w160" placeholder="请输入" v-model="item.kzcs3"></el-input>
																	</el-form-item>
																</el-col>
															</template>
														</el-row>
													</el-form>
												</div>
											</template>
										</el-form>
									</div>
								</div>
							</div>
						</div>
						<div style="margin-bottom: 10px;"><creat-file :form="form"></creat-file></div>
					</basic-container>
				</div>
			</el-col>
			<el-col :span="6" style="margin-top:10px;"><creat-flow ref="creatFlow" :formList="formList"></creat-flow></el-col>
		</el-row>
		<steps ref="steps" @close="success()" :nowdate="nowdate"></steps>
		<confirm
			ref="confirm"
			@close="save()"
			type="1"
			:guifanFilesProcessRecordList="guifanFilesProcessRecordList"
			:systemGuifanFilesProcessList="systemGuifanFilesProcessList"
		></confirm>
		<showhistory ref="showhistory" type="1" :guifanFilesProcessRecordList="guifanFilesProcessRecordList"></showhistory>
	</detailbox>
</template>

<script>
const jhdata = require('./components/jhdata.js');
import wyy from './components/wyy.vue';
import confirm from './confirm.vue';
import { savefiles, getguifanDetail, update, getguifanList } from '@/api/myapi/tixiwenjian';
export default {
	props: {
		detailId: '',
		type: {
			type: [Number, String],
			default: 0
		}
	},
	components: {
		confirm,
		wyy
	},
	data() {
		return {
			jhdata,
			developmentplanList: [],
			wxyList: [],
			sjxlList: [],
			wxqkList: [],
			shList: [],
			system: 'riskprocess',
			formList: [
				{
					numberType: 0,
					memberOption: [],
					controlList: [{}],
					jiluFileList: [],
					guifanFileList: []
				}
			],
			guifanFilesProcessRecordList: [],
			systemGuifanFilesProcessList: []
		};
	},
	created() {
		if (this.detailId) {
			this.getDetail();
		} else {
			this.findTypeByProcessType();
		}
		this.getdeptlist();

		this.getMainDataList();
		this.getdevelopmentplanList();
	},
	methods: {
		getDetail() {
			getguifanDetail(
				{
					id: this.detailId
				},
				this.system
			).then(({ data }) => {
				console.log(data);
				if (data.success) {
					if (this.type == 2) {
						delete data.data.id;
						data.data.number = '';
						data.data.numberType = 0;
						this.findTypeByProcessType();
					}
					this.formList = [data.data];
					this.formList.forEach(item => {
						this.getuserByDept(item.manageDeptId, item);
					});
					this.guifanFilesProcessRecordList = data.data.processRecordList;
					this.checkItem = this.guifanFilesProcessRecordList.find(item => item.checkStatus == 2);
					this.$nextTick(() => {
						this.$refs.creatFlow.setProcessRecord(this.guifanFilesProcessRecordList);
					});
				}
			});
		},
		// 控制表相关数据
		getMainDataList() {
			getguifanList(
				{
					current: 1,
					size: 10000,
					descs: 'create_time'
				},
				'riskanalyzecontrol'
			).then(({ data }) => {
				console.log('控制表');
				if (data && data.success) {
					let dataList = data.data.records;
					this.wxyList = new Set(
						this.mapFu(dataList, 'wxy1')
							.concat(this.mapFu(dataList, 'wxy2'))
							.concat(this.mapFu(dataList, 'wxy3'))
					);
					this.sjxlList = new Set(
						this.mapFu(dataList, 'sjxl1')
							.concat(this.mapFu(dataList, 'sjxl2'))
							.concat(this.mapFu(dataList, 'sjxl3'))
					);
					this.wxqkList = new Set(
						this.mapFu(dataList, 'wxqk1')
							.concat(this.mapFu(dataList, 'wxqk2'))
							.concat(this.mapFu(dataList, 'wxqk3'))
					);
					this.shList = new Set(
						this.mapFu(dataList, 'sh1')
							.concat(this.mapFu(dataList, 'sh2'))
							.concat(this.mapFu(dataList, 'sh3'))
					);
				}
			});
		},
		mapFu(arry, key) {
			let newDataList = arry.filter(item => item[key]);
			return newDataList.map(item => item[key]);
		},
		// 风险管理计划
		getdevelopmentplanList() {
			getguifanList(
				{
					current: 1,
					size: 10000,
					processStatus: 7
				},
				'riskplanprocess'
			).then(({ data }) => {
				console.log('风险管理计划');
				console.log(data);
				if (data && data.success) {
					this.developmentplanList = data.data.records;
				}
			});
		},
		//   选择风险
		changfxitem(id, type, item, k1, k2, k3) {
			if (type == 'fxyzd') {
				item[k1] = id;
			} else {
				item[k2] = id;
			}
			// A:可接受的风险（X1+X2） // U:不可接受的风险（X1+X2）// X1是指:严重度水平分级 // X2是指:概率分级
			if (item[k1] && item[k2]) {
				let riskAssessment = jhdata.fxpj[item[k2]][item[k1]];
				if (riskAssessment == 'A') {
					item[k3] = `A:可接受的风险(${item[k1]}+${item[k2]})`;
				} else {
					item[k3] = `U:不可接受的风险(${item[k1]}+${item[k2]})`;
				}
			}
		},
		changplan(id, form) {
			let nodes = this.developmentplanList.find(item => item.number == id);
			console.log(nodes);
			form.name = nodes.name;
			form.productName = nodes.productName;
			form.productCode = nodes.productCode;
			form.skus = nodes.skus;
		},
		close() {
			this.$emit('close');
		},
		getMemberOption(val, index) {
			let dept = this.$refs.newdept[index].getCheckedNodes();
			this.formList[index].manageDeptName = dept[0].label;
			this.formList[index].manageDeptId = dept[0].value;
			this.formList[index].manageUserId = '';
			this.formList[index].manageUserName = '';
			this.getuserByDept(val, this.formList[index]);
		},
		submit() {
			let systemGuifanFilesProcessList = [];
			let guifanFilesProcessRecordList = this.$refs.creatFlow.guifanFilesProcessRecordList;
			let isOnlineReview = this.$refs.creatFlow.isOnlineReview;
			for (let i = 0; i <= guifanFilesProcessRecordList.length - 1; i++) {
				let item = guifanFilesProcessRecordList[i];
				item.sort=i;
				if (item.type == 1 && !item.userId) {
					this.$message.error('请选择审核人员');
					return;
				}
				if (item.type == 4 && !item.userId) {
					this.$message.error('请选择批准人员');
					return;
				}
				if (isOnlineReview && item.type == 3 && !item.userId) {
					this.$message.error('请选择记录责任人');
					return;
				}
			}
			for (let i = 0; i < this.formList.length; i++) {
				let item = this.formList[i];

				for (let m = 0; m < item.controlList.length; m++) {
					let mitem = item.controlList[m];
					let arr = [
						{
							value: mitem.wxy1,
							tips: '请补充危险（源）'
						},
						{
							value: mitem.sjxl1,
							tips: '请补充事件序列'
						},
						{
							value: mitem.wxqk1,
							tips: '请补充危险情况'
						},
						{
							value: mitem.sh1,
							tips: '请补充伤害'
						},
						{
							value: mitem.glfj1,
							tips: '请选择概率分级'
						},
						{
							value: mitem.yzfj1,
							tips: '请补充严重度水平分级'
						},
						{
							value: mitem.syfx1,
							tips: '请选择是否有剩余风险'
						}
					];
					for (let n = 0; n < arr.length; n++) {
						if (!arr[n].value) {
							this.$message.error(arr[n].tips);
							return;
						}
					}
				}
				let arr = [
					{
						value: item.number,
						tips: '请补充风险管理编号'
					},
					{
						value: item.name,
						tips: '请补充风险管理名称'
					},
					{
						value: item.planNumber,
						tips: '请补充风险计划管理编号'
					},
					{
						value: item.manageDeptId,
						tips: '请选择管理部门'
					},
					{
						value: item.manageUserId,
						tips: '请选择负责人'
					},
					{
						value: item.jiluFilesIds,
						tips: '请添加记录文件'
					},
					{
						value: item.retentionPeriod,
						tips: '请输入记录保留期限'
					},
					{
						value: item.retentionPeriod < 2 ? false : true,
						tips: '记录保留期限应≥2年'
					}
				];
				for (let j = 0; j < arr.length; j++) {
					if (!arr[j].value) {
						this.$message.error(arr[j].tips);
						return;
					}
				}
				item.createDeptName = this.userInfo.deptName;
				item.createUserName = this.userInfo.user_name;
				item.createUserId = this.userInfo.user_id;
				item.createDeptId = this.userInfo.dept_id;
				systemGuifanFilesProcessList.push({
					...item,
					// depts: item.depts.join(','),
					processRecordList: guifanFilesProcessRecordList
				});
			}
			this.systemGuifanFilesProcessList = systemGuifanFilesProcessList;
			this.guifanFilesProcessRecordList = guifanFilesProcessRecordList;
			console.log(this.systemGuifanFilesProcessList);
			console.log(this.guifanFilesProcessRecordList);
			this.openDialg('confirm');
		},
		// 保存
		save() {
			if (this.type == 1) {
				update(this.systemGuifanFilesProcessList, this.system).then(({ data }) => {
					if (data.success) {
						this.$message.success('提交成功');
						this.nowdate = this.dateFormat(new Date());
						this.openDialg('steps');
					}
				});
			} else {
				// console.log(JSON.stringify(this.systemGuifanFilesProcessList));
				savefiles(this.systemGuifanFilesProcessList, this.system).then(({ data }) => {
					if (data.success) {
						this.$message.success('提交成功');
						this.nowdate = this.dateFormat(new Date());
						this.openDialg('steps');
					}
				});
			}
		},
		success() {
			this.$emit('success');
		},
		addList(form) {
			form.controlList.push({});
		},
		// 发放的文件
		addFile() {
			this.formList.push({
				memberOption: [],
				numberType: this.numberType,
				number: this.numberType == 0 ? this.findTypeByProcessType(this.liushuihao) : '',
				jiluFileList: [],
				guifanFileList: [],
				controlList: [{}]
			});
			let index = this.formList.length - 1;
			setTimeout(() => {
				let document = window.parent.document.getElementById(`item${index}`);
				document.scrollIntoView({ behavior: 'smooth' });
			}, 100);
		}
	}
};
</script>

<style scoped="scoped" lang="scss">
.btnbox {
	border: 1px solid #a3cffd;
	opacity: 1;
	border-radius: 3px 0px 0px 3px;
}

.btnleft {
	padding: 0 10px;
}

.btnright {
	border-left: 1px solid #a3cffd;
	padding: 0 10px;
	line-height: 32px;
}

.border {
	border: 1px solid #dcdfe6;
	border-radius: 4px;
	line-height: 32px;
	padding: 0 10px;
}

.preview {
	padding: 10px;
	background-color: #f0f2f5;
	margin-top: 20px;
	margin-left: 10px;
}

.preview .warn_f {
	background-color: #fbf4e0;
	border: 1px solid #f3dea4;
	line-height: 20px;
	padding: 0 4px;
	margin: 20px 0 10px;
}

.preview .tem {
	width: 377px;
	height: 512px;
}

.preview.bigpreview {
	background-color: #ffffff;
}

.preview.bigpreview .tem {
	width: 510px;
	height: 693px;
}

.error {
	background-color: #fceeec;
	border: 1px solid #f9dcd9;
	padding: 6px 10px;
	border-radius: 2px;
}

div::deep .el-checkbox.is-bordered {
	height: 32px;
	padding: 5px 10px;
}

.fileBox {
	position: relative;
	padding: 20px 10px 1px;
	border: 1px dashed #e4e8ed;

	.del {
		position: absolute;
		right: 10px;
		top: 10px;
	}
}

.worktable {
	td,
	th {
		line-height: 28px;
	}
}

.steps {
	.f16 {
		margin-left: 6px;
	}

	.flex_center {
		margin-bottom: 7px;
	}
}

.btnbox {
	border: 1px solid #a3cffd;
	opacity: 1;
	border-radius: 3px 0px 0px 3px;
}

.btnleft {
	padding: 0 10px;
}

.btnright {
	border-left: 1px solid #a3cffd;
	padding: 0 10px;
	line-height: 32px;
}

.border {
	border: 1px solid #dcdfe6;
	border-radius: 4px;
	line-height: 32px;
	padding: 0 10px;
}

.preview {
	padding: 10px;
	background-color: #f0f2f5;
	margin-top: 20px;
	margin-left: 10px;
}

.preview .warn_f {
	background-color: #fbf4e0;
	border: 1px solid #f3dea4;
	line-height: 20px;
	padding: 0 4px;
	margin: 20px 0 10px;
}

.preview .tem {
	width: 377px;
	height: 512px;
}

.preview.bigpreview {
	background-color: #ffffff;
}

.preview.bigpreview .tem {
	width: 510px;
	height: 693px;
}

.error {
	background-color: #fceeec;
	border: 1px solid #f9dcd9;
	padding: 6px 10px;
	border-radius: 2px;
}

div::deep .el-checkbox.is-bordered {
	height: 32px;
	padding: 5px 10px;
}

.jobfile {
	margin-top: 20px;
	display: flex;
	justify-content: center;
}

.jobLeft {
	width: 34%;
}

.leftTitle {
	height: 48px;
	background: #f5f7fa;
	border: 1px solid #ebf0f5;
	opacity: 1;
	line-height: 48px;
	border-radius: 0px;
	padding: 0 15px;
	font-size: 14px;
	font-family: Microsoft YaHei;
	font-weight: 400;
	color: #303133;
	opacity: 1;
}

.leftList {
	height: 98px;
	background: #ffffff;
	border: 1px solid #ebf0f5;
	opacity: 1;
	line-height: 95px;
	border-radius: 0px;
	display: flex;
	justify-content: flex-start;
	align-items: center;
	padding: 0 15px;
}

.cenList {
	height: 48px;
	background: #ffffff;
	border: 1px solid #ebf0f5;
	opacity: 1;
	line-height: 48px;
	padding: 0 15px;
	display: flex;
	justify-content: flex-start;
	align-items: center;
	border-radius: 0px;
}

.fileBtn {
	margin-left: auto;
	margin-right: 10px;
	font-size: 12px;
	font-family: Microsoft YaHei;
	font-weight: 400;
	line-height: 16px;
	color: #909499;
	opacity: 1;
}

.leftBtn {
	margin-left: auto;
	margin-right: 10px;
}

.leftText {
	font-size: 14px;
	font-family: Microsoft YaHei;
	font-weight: 400;
	line-height: 16px;
	color: #606366;
	opacity: 1;
}

.reviewTitle {
	font-size: 14px;
	font-family: Microsoft YaHei;
	font-weight: bold;
	line-height: 0px;
	color: #606366;
	opacity: 1;
	margin-top: 30px;
}

.addReview {
	width: 74px;
	height: 32px;
	margin: 0 20px;
	background: #e6f1fc;
	border: 1px solid #a3cffd;
	opacity: 1;
	border-radius: 3px;
	font-size: 14px;
	font-family: Microsoft YaHei;
	font-weight: 400;
	line-height: 14px;
	color: #126bc9;
	display: flex;
	justify-content: center;
	align-items: center;
}

.reviewText {
	font-size: 12px;
	font-family: Microsoft YaHei;
	font-weight: 400;
	line-height: 18px;
}

.reviewList {
	// background: #ffffff;
	border: 1px dashed #e4e8ed;
	border-radius: 0px;
	padding: 15px;
}
</style>
